// import com.alibaba.druid.sql.ast.SQLHint;
// import com.alibaba.druid.sql.ast.statement.SQLTableSourceImpl;
// import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
// import com.alibaba.druid.sql.visitor.SQLASTVisitor;

#include "MySqlUpdateTableSource.h"
#include "MySqlUpdateStatement.h"
#include "../../../../../utils/instanceof.h"
#include "../../visitor/MySqlASTVisitor.h"
#include "../../../../visitor/SQLASTVisitor.h"
#include "../../../../ast/SQLHint.h"
#include "../../../../../Exception/IllegalArgumentException.h"

MySqlUpdateTableSource::MySqlUpdateTableSource(MySqlUpdateStatement_ptr update)
{
  this->update = update;
}

// @Override
void MySqlUpdateTableSource::accept0(SQLASTVisitor_ptr visitor)
{
  if (instanceof <SQLASTVisitor, MySqlASTVisitor>(visitor))
  {
    accept0(std::dynamic_pointer_cast<MySqlASTVisitor>(visitor));
  }
  else
  {
    std::string tmp = "not support visitor type : ";
    tmp += visitor->getClass()->c_str();
    throw new IllegalArgumentException(make_string_ptr(tmp));
  }
}

void MySqlUpdateTableSource::accept0(MySqlASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(MySqlUpdateTableSource)))
  {
    acceptChild(visitor, update);
  }
  visitor->endVisit(SharedObject(MySqlUpdateTableSource));
}

MySqlUpdateStatement_ptr MySqlUpdateTableSource::getUpdate()
{
  return update;
}

void MySqlUpdateTableSource::setUpdate(MySqlUpdateStatement_ptr update)
{
  this->update = update;
}

// @Override
SQLObject_ptr MySqlUpdateTableSource::clone()
{
  SQLObject_ptr clone_tmp = std::shared_ptr<MySqlUpdateTableSource>(new MySqlUpdateTableSource(this->update));
  std::shared_ptr<MySqlUpdateTableSource> x = std::dynamic_pointer_cast<MySqlUpdateTableSource>(clone_tmp);
  // MySqlUpdateTableSource x = new MySqlUpdateTableSource(this->update);

  x->setAlias(this->alias);

  if (this->flashback != nullptr)
  {
    x->setFlashback(std::dynamic_pointer_cast<SQLExpr>(this->flashback->clone()));
  }

  if (this->hints != nullptr)
  {
    for (SQLHint_ptr e : *this->hints)
    {
      SQLHint_ptr e2 = std::dynamic_pointer_cast<SQLHint>(e->clone());
      e2->setParent(x);
      x->getHints()->push_back(e2);
    }
  }

  return x;
}
